<?php
/**
 * Created by PhpStorm.
 * User: deng
 * Date: 2016/11/8
 * Time: 15:05
 */
class AnonymousModel{

    const ANONYMOUS_KEY_PREFIX = 'AYS/';
    const FAVORITE_KEY_PREFIX = 'AYSF/';
    const COMMENT_KEY_PREFIX = 'AYSC/';
    const MESSAGE_KEY_PREFIX = 'AYSM/';

    const CC_ANONYMOUS_KEY = 'ays:';
    const LIKE_ANONYMOUS_KEY = 'aysl:';

    protected $bg_type_range = ['color', 'image'];
    private $diaryListCacheModel;

    private $default_name_code = [
        '0' => 'name',
        //刀剑乱舞
        '1' => ['1001' => '今剑', '1002' => '平野藤四郎', '1003' => '厚藤四郎', '1004' => '信浓藤四郎', '1005' => '前天藤四郎', '1006' => '秋田藤四郎', '1007' => '博多藤四郎', '1008' => '乱藤四郎', '1009' => '五虎退', '1010' => '药研藤四郎', '1011' => '爱染国俊', '1012' => '太鼓钟贞宗', '1013' => '小夜左文字', '1014' => '不动行光', '1015' => '笑面青江', '1016' => '鲶尾藤四郎', '1017' => '骨喰藤四郎', '1018' => '物吉贞宗', '1019' => '堀川国广', '1020' => '浦岛虎彻', '1021' => '鸣狐', '1022' => '宗三左文字', '1023' => '加州清光', '1024' => '大和守安定', '1025' => '歌仙兼定', '1026' => '和泉守兼定', '1027' => '陆奥守吉行', '1028' => '山姥切国广', '1029' => '蜂须贺虎彻', '1030' => '长曾祢虎彻', '1031' => '大倶利伽罗', '1032' => '压切长谷部', '1033' => '同田贯正国', '1034' => '三日月宗近', '1035' => '小狐丸', '1036' => '数珠丸恒次', '1037' => '一期一振', '1038' => '莺丸', '1039' => '明石国行', '1040' => '烛台切光忠　', '1041' => '江雪左文字', '1042' => '山伏国广', '1043' => '髭切', '1044' => '膝丸', '1045' => '狮子王', '1046' => '鹤丸国永', '1047' => '石切丸', '1048' => '萤丸', '1049' => '太郎太刀', '1050' => '次郎太刀', '1051' => '蜻蛉切', '1052' => '日本号', '1053' => '御手杵', '1054' => '岩融'],
        //斗破苍穹
        '2' => ['2001' => '萧炎', '2002' => '萧薰儿', '2003' => '药老', '2004' => '纳兰嫣然', '2005' => '小医仙', '2006' => '萧玉', '2007' => '萧宁', '2008' => '雅妃', '2009' => '萧鼎', '2010' => '萧厉', '2011' => '云芝', '2012' => '云韵', '2013' => '青鳞', '2014' => '海波东', '2015' => '云山', '2016' => '美杜莎女王', '2017' => '凌师', '2018' => '神秘斗皇', '2019' => '法犸', '2020' => '若琳导师', '2021' => '学院妖女', '2022' => '奥托　', '2023' => '雪魅', '2024' => '琳菲', '2025' => '蛇女月媚', '2026' => '红裙女子', '2027' => '盐城红衣女子灵琳', '2028' => '绿蛮', '2029' => '白牙', '2030' => '紫妍 ', '2031' => '韩雪 ', '2032' => '韩月 ', '2033' => '曹颖  ', '2034' => '曹休 ', '2035' => '萧晨 ', '2036' => '加刑天  ', '2037' => '古河 ', '2038' => '柳翎 ', '2039' => '吴昊  ', '2040' => '林修崖 ', '2041' => '琥嘉 ', '2042' => '柳擎 ', '2043' => '林焱 ', '2044' => '叶欣蓝 ', '2045' => '翎泉 ', '2046' => '苏千 ', '2047' => '邙天尺 ', '2048' => '墨承 ', '2049' => '凤清儿 ', '2050' => '风闲 ', '2051' => '唐火儿 ', '2052' => '妖花邪君 ', '2053' => '幽泉'],
        //狗
        '3' => ['3001' => '哈士奇', '3002' => '边境牧羊', '3003' => '柯基', '3004' => '萨摩耶', '3005' => '巴哥', '3006' => '松狮', '3007' => '澳洲牧羊', '3008' => '吉娃娃', '3009' => '拉萨犬', '3010' => '马尔济斯', '3011' => '贵宾犬', '3012' => '金毛', '3013' => '阿拉斯加', '3014' => '法国斗牛', '3015' => '英国斗牛', '3016' => '大麦町', '3017' => '藏獒', '3018' => '蝴蝶', '3019' => '德国牧羊', '3020' => '秋田', '3021' => '柴犬', '3022' => '墨梅', '3023' => '杜宾', '3024' => '大丹犬', '3025' => '卡斯罗', '3026' => '罗威纳', '3027' => '阿富汗', '3028' => '腊肠', '3029' => '西施', '3030' => '大白熊', '3031' => '圣伯纳', '3032' => '法老王', '3033' => '斗牛梗', '3034' => '西高地', '3035' => '比熊', '3036' => '纽芬兰', '3037' => '北京犬', '3038' => '喜乐蒂', '3039' => '米格鲁', '3040' => '伯恩山', '3041' => '惠比特', '3042' => '贝灵顿', '3043' => '冠毛犬', '3044' => '杰克罗素', '3045' => '拉布拉多', '3046' => '万能梗', '3047' => '波音全', '3048' => '约克夏', '3049' => '沙皮', '3050' => '可卡', '3051' => '巴吉度', '3052' => '雪纳瑞', '3053' => '古代牧羊', '3054' => '丝毛梗', '3055' => '拳师犬'],
        //黑子的篮球
        '4' => ['4001' => '黑子', '4002' => '火神', '4003' => '日向', '4004' => '水户部', '4005' => '小金井', '4006' => '土田', '4007' => '伊月', '4008' => '木吉', '4009' => '相田', '4010' => '哲也', '4011' => '大我', '4012' => '顺平', '4013' => '凛之助', '4014' => '慎二', '4015' => '聪史', '4016' => '俊', '4017' => '铁平', '4018' => '丽子', '4019' => '黄濑', '4020' => '凉太', '4021' => '笠松', '4022' => '幸男', '4023' => '绿间', '4024' => '真太郎', '4025' => '高尾', '4026' => '和成', '4027' => '青峰', '4028' => '大辉', '4029' => '桃井', '4030' => '五月', '4031' => '今吉', '4032' => '翔一', '4033' => '紫原', '4034' => '敦', '4035' => '冰室', '4036' => '辰也', '4037' => '荒木', '4038' => '雅子', '4039' => '赤司', '4040' => '征十郎', '4041' => '实渕', '4042' => '玲央', '4043' => '叶山', '4044' => '小太郎', '4045' => '阿列克斯', '4046' => '灰崎', '4047' => '祥吾', '4048' => '荻原', '4049' => '成浩'],
        //后宫阶品
        '5' => ['5001' => '皇帝', '5002' => '中宫皇后', '5003' => '东宫皇后', '5004' => '西宫皇后', '5005' => '御皇贵妃', '5006' => '尊皇贵妃', '5007' => '皇贵妃', '5008' => '贵妃', '5009' => '淑妃', '5010' => '贤妃', '5011' => '德妃', '5012' => '宁妃', '5013' => '慧妃', '5014' => '皇夫人', '5015' => '贵嫔', '5016' => '昭仪', '5017' => '昭容', '5018' => '昭媛', '5019' => '修仪', '5020' => '修容', '5021' => '修媛', '5022' => '充仪', '5023' => '淑仪', '5024' => '充容', '5025' => '充媛', '5026' => '顺仪', '5027' => '淑媛', '5028' => '顺容', '5029' => '顺媛', '5030' => '嫔', '5031' => '婕妤', '5032' => '容华', '5033' => '婉仪', '5034' => '德仪', '5035' => '贵人', '5036' => '才人', '5037' => '美人', '5038' => '常在', '5039' => '选侍', '5040' => '答应', '5041' => '小主', '5042' => '秀女', '5043' => '圣英皇太后', '5044' => '圣明皇太后', '5045' => '御皇太妃', '5046' => '尊皇太妃', '5047' => '皇太妃', '5048' => '贵太妃', '5049' => '太妃', '5050' => '御国长公主', '5051' => '尊国长公主', '5052' => '镇国长公主', '5053' => '辅国长公主 ', '5054' => '定国长公主 ', '5055' => '固伦长公主', '5056' => '固宁长公主', '5057' => '孝和长公主', '5058' => '孝轩长公主', '5059' => '和硕长公主', '5060' => '和林长公主', '5061' => '御公主', '5062' => '尊公主', '5063' => '皇公主', '5064' => '德公主', '5065' => '孝公主', '5066' => '静公主', '5067' => '正公主', '5068' => '固伦公主', '5069' => '和硕公主', '5070' => '安公主', '5071' => '海公主', '5072' => '琰公主', '5073' => '御国皇子', '5074' => '尊国皇子', '5075' => '镇国皇子', '5076' => '定国皇子', '5077' => '辅国皇子', '5078' => '卿国皇子', '5079' => '正皇子', '5080' => '皇子正妃', '5081' => '皇子尊妃', '5082' => '皇子侧妃', '5083' => '皇子偏妃', '5084' => '皇子小妃', '5085' => '摄政王', '5086' => '辅政王', '5087' => '镇国公', '5088' => '御国公', '5089' => '辅国公', '5090' => '护国公', '5091' => '兴国公', '5092' => '安国公', '5093' => '建极侯', '5094' => '王爷正妃', '5095' => '王爷尊妃', '5096' => '王爷侧妃', '5097' => '王爷偏妃', '5098' => '王爷小妃', '5099' => '御郡主', '5100' => '尊郡主', '5101' => '皇郡主', '5102' => '和郡主', '5103' => '孝郡主', '5104' => '固郡主', '5105' => '琰郡主', '5106' => '宁郡主', '5107' => '宜郡主', '5108' => '平郡主', '5109' => '祺郡主', '5110' => '灵郡主', '5111' => '惜郡主', '5112' => '安郡主', '5113' => '逸郡主', '5114' => '右丞相', '5115' => '左丞相', '5116' => '太师', '5117' => '太保', '5118' => '大学士', '5119' => '将军', '5120' => '内禁卫将', '5121' => '文提督', '5122' => '武提督', '5123' => '副将军', '5124' => '内禁卫副将', '5125' => '各省总督', '5126' => '礼部侍郎', '5127' => '工部侍郎', '5128' => '巡抚', '5129' => '内阁学士', '5130' => '知府', '5131' => '县令', '5132' => '尚仪', '5133' => '尚服', '5134' => '尚食', '5135' => '尚寝', '5136' => '尚仪总管', '5137' => '尚仪主事', '5138' => '尚仪管事', '5139' => '尚仪长使', '5140' => '尚仪中使', '5141' => '尚仪少使', '5142' => '尚仪提调', '5143' => '尚仪姑姑', '5144' => '尚仪宫女', '5145' => '尚服总管', '5146' => '尚服主事', '5147' => '尚服管事', '5148' => '尚服长使', '5149' => '尚服中使', '5150' => '尚服少使', '5151' => '尚服提调', '5152' => '尚服姑姑', '5153' => '尚服宫女', '5154' => '尚食总管', '5155' => '尚食主事', '5156' => '尚食管事', '5157' => '尚食长使', '5158' => '尚食中使', '5159' => '尚食少使', '5160' => '尚食提调', '5161' => '尚食姑姑', '5162' => '尚食宫女', '5163' => '尚寝总管', '5164' => '尚寝主事', '5165' => '尚寝管事', '5166' => '尚寝长使', '5167' => '尚寝中使', '5168' => '尚寝少使', '5169' => '尚寝提调', '5170' => '尚寝姑姑', '5171' => '尚寝宫女', '5172' => '首席侍卫', '5173' => '殿前侍卫', '5174' => '高级侍卫', '5175' => '中级侍卫', '5176' => '初级侍卫', '5177' => '皇室侍卫', '5178' => '贴身侍卫', '5179' => '普通侍卫', '5180' => '宫女总管', '5181' => '提调宫女', '5182' => '大殿宫女', '5183' => '调教宫女', '5184' => '小宫女', '5185' => '医女总管', '5186' => '提调医女', '5187' => '高级宫女', '5188' => '中级宫女', '5189' => '调教医女', '5190' => '小医女'],
        //花千骨
        '6' => ['6001' => '白子画', '6002' => '花千骨', '6003' => '杀阡陌', '6004' => '东方彧卿', '6005' => '糖宝', '6006' => '紫熏浅夏', '6007' => '轻水', '6008' => '幽若', '6009' => '朔风', '6010' => '蓝雨澜风', '6011' => '落十一', '6012' => '轩辕朗', '6013' => '火夕', '6014' => '舞青萝', '6015' => '狐青丘', '6016' => '上上飘', '6017' => '朽木清流', '6018' => '云隐', '6019' => '云翳', '6020' => '墨冰仙', '6021' => '竹染', '6022' => '南无月', '6023' => '霓漫天', '6024' => '哼唧兽', '6025' => '烈行云', '6026' => '张大夫', '6027' => '花秀才', '6028' => '林随意', '6029' => '绿鞘', '6030' => '洛河东', '6031' => '轩辕沧', '6032' => '清虚道长', '6033' => '玉帝', '6034' => '王母', '6035' => '清怜', '6036' => '清怀', '6037' => '东华上仙  ', '6038' => '幻夕颜 ', '6039' => '桃翁', '6040' => '屈木', '6041' => '霓千丈'],
        //猫
        '7' => ['7001' => '暹罗猫', '7002' => '布偶猫', '7003' => '苏格兰折耳', '7004' => '英短', '7005' => '美短', '7006' => '波斯猫', '7007' => '异国短毛', '7008' => '孟买猫', '7009' => '异国长毛', '7010' => '埃及猫', '7011' => '缅因猫', '7012' => '挪威森林', '7013' => '伯曼猫', '7014' => '斯芬克斯', '7015' => '缅甸猫', '7016' => '新加坡猫', '7017' => '索马里猫', '7018' => '狸花', '7019' => '三花猫', '7020' => '虎斑猫', '7021' => '狮子猫', '7022' => '豹猫', '7023' => '云猫', '7024' => '玄猫', '7025' => '美国短尾', '7026' => '日本短尾', '7027' => '巴厘猫', '7028' => '沙特耳猫', '7029' => '卷耳猫', '7030' => '拿破仑猫', '7031' => '黑猫', '7032' => '白猫', '7033' => '黄猫', '7034' => '蓝猫', '7035' => '土猫'],
        //三生三世&择天记
        '8' => ['8001' => '白浅/司音', '8002' => '夜华', '8003' => '凤九', '8004' => '素锦', '8005' => '叠风', '8006' => '东华', '8007' => '阿离', '8008' => '墨渊', '8009' => '折颜', '8010' => '白真', '8011' => '白奕', '8012' => '白玄', '8013' => '擎苍', '8014' => '子阑', '8015' => '司命星君', '8016' => '胭脂', '8017' => '少辛', '8018' => '连宋', '8019' => '离怨', '8020' => '迷谷', '8021' => '离境', '8022' => '令羽', '8023' => '玄女', '8024' => '陈长生', '8025' => '莫雨', '8026' => '徐有容', '8027' => '唐山十六', '8028' => '落落', '8029' => '折袖', '8030' => '圣后', '8031' => '唐棠', '8032' => '秋山君'],
        //数码宝贝
        '9' => ['9001' => '豆苗兽 ', '9002' => '比高兽 ', '9003' => '比丘兽 ', '9004' => '巴多拉兽 ', '9005' => '伽楼达兽 ', '9006' => '凤凰兽', '9007' => '亚古兽', '9008' => '加奥兽 ', '9009' => '拉拉兽 ', '9010' => '猎鹰兽', '9011' => '滚球兽', '9012' => '独角兽', '9013' => '种子兽', '9014' => '比高兽', '9015' => '年糕兽', '9016' => '迪哥兽', '9017' => '布加兽', '9018' => '咪罗兽', '9019' => '豆丁兽 ', '9020' => '亚古兽 ', '9021' => '加布兽', '9022' => '巴鲁兽', '9023' => '比丘兽', '9024' => '甲虫兽 ', '9025' => '巴达兽', '9026' => '哥玛兽', '9027' => '小狗兽 ', '9028' => 'V仔兽', '9029' => '麻鹰兽 ', '9030' => '穿山兽', '9031' => '虫虫兽', '9032' => '暴龙兽 ', '9033' => '加鲁鲁兽', '9034' => '仙人掌兽', '9035' => '比多兽', '9036' => '天使兽 ', '9037' => '海狮兽', '9038' => '迪路兽 ', '9039' => '亚古拉兽', '9040' => '战甲兽', '9041' => '飞虫兽 ', '9042' => '狮子兽', '9043' => '熊仔兽 ', '9044' => '机械暴龙', '9045' => '加鲁鲁 ', '9046' => '花仙兽 ', '9047' => '伽楼达兽', '9048' => '超比多兽', '9049' => '神圣天使', '9050' => '天女兽', '9051' => '机甲龙兽', '9052' => '古神兽', '9053' => '悟空兽', '9054' => '祭师兽 ', '9055' => '安杜路兽', '9056' => '大古拉兽', '9057' => '恶霸熊仔 ', '9058' => '小丑皇 ', '9059' => '木偶兽'],
        //王者荣耀
        '10' => ['10001' => '黄忠', '10002' => '诸葛亮', '10003' => '哪吒', '10004' => '太乙真人', '10005' => '样机', '10006' => '成吉思汗', '10007' => '橘右京', '10008' => '马可波罗', '10009' => '雅典娜', '10010' => '夏侯淳', '10011' => '蔡文姬', '10012' => '关羽', '10013' => '虞姬', '10014' => '安琪拉', '10015' => '项羽', '10016' => '后羿', '10017' => '刘禅', '10018' => '王昭君', '10019' => '赵云', '10020' => '花木兰', '10021' => '狄仁杰', '10022' => '韩信', '10023' => '墨子', '10024' => '鲁班七号', '10025' => '宫本武藏', '10026' => '牛魔', '10027' => '貂蝉', '10028' => '典韦', '10029' => '小瞧', '10030' => '甄姬', '10031' => '妲己', '10032' => '孙膑', '10033' => '武则天', '10034' => '高渐离', '10035' => '吕布', '10036' => '孙悟空', '10037' => '孙尚香', '10038' => '达摩', '10039' => '程咬金', '10040' => '扁鹊', '10041' => '亚瑟', '10042' => '荆轲', '10043' => '姜子牙', '10044' => '周瑜', '10045' => '老夫子', '10046' => '嬴政', '10047' => '曹操', '10048' => '庄周', '10049' => '张良', '10050' => '钟无艳', '10051' => '芈月', '10052' => '露娜', '10053' => '廉颇', '10054' => '白起', '10055' => '张飞', '10056' => '刘备', '10057' => '兰陵王', '10058' => '娜可露露', '10059' => '礼拜', '10060' => '钟馗', '10061' => '李元芳', '10062' => '刘邦', '10063' => '不知火舞'],
        //微微一笑很倾城&旋风少女
        '11' => ['11001' => '肖奈', '11002' => '贝微微', '11003' => '曹光', '11004' => '郝眉', '11005' => '于半珊', '11006' => '孟逸然', '11007' => '二喜', '11008' => '余淮', '11009' => '耿耿', '11010' => '路星河', '11011' => '蒋年年', '11012' => '简单', '11013' => '韩叙', '11014' => '裴尚轩', '11015' => '黎璃', '11016' => '柳千仁', '11017' => '韩以晨', '11018' => '丹尼尔', '11019' => '李君', '11020' => '顾若白', '11021' => '戚百草', '11022' => '方廷皓', '11023' => '喻初原', '11024' => '方婷宜', '11025' => '范晓萤', '11026' => '胡亦枫', '11027' => '曲向南', '11028' => '金敏珠', '11029' => '李恩秀', '11030' => '长安'],
        //学校组织
        '12' => ['12001' => '学校组织', '12002' => '校长', '12003' => '教导主任', '12004' => '班主任', '12005' => '数学老师', '12006' => '语文老师', '12007' => '英语老师', '12008' => '物理老师', '12009' => '化学老师', '12010' => '生物老师', '12011' => '政治老师', '12012' => '历史老师', '12013' => '地理老师', '12014' => '音乐老师', '12015' => '体育老师', '12016' => '学生会成员', '12017' => '学生会主席', '12018' => '副主席', '12019' => '秘书长', '12020' => '宣传部部长', '12021' => '社团部部长', '12022' => '文艺部部长', '12023' => '体育部部长', '12024' => '班长 ', '12025' => '副班长', '12026' => '学习委员 ', '12027' => '纪律委员  ', '12028' => '劳动委员 ', '12029' => '心理委员', '12030' => '班花（女）', '12031' => '班草（男）'],
        //阴阳师
        '13' => ['13001' => '安倍晴明', '13002' => '神乐', '13003' => '源博雅', '13004' => '八百比丘尼', '13005' => '茨木童子', '13006' => '大天狗', '13007' => '荒川之主', '13008' => '酒吞童子', '13009' => '两面佛', '13010' => '青行灯', '13011' => '阎摩', '13012' => '小鹿男', '13013' => '妖刀姬', '13014' => '白狼', '13015' => '二口女', '13016' => '凤凰火', '13017' => '骨女', '13018' => '鬼女红叶', '13019' => '鬼使白', '13020' => '鬼使黑', '13021' => '海坊主', '13022' => '妖狐', '13023' => '傀儡师', '13024' => '孟婆', '13025' => '判官', '13026' => '清姬', '13027' => '犬神', '13028' => '食梦貘', '13029' => '桃花妖', '13030' => '跳跳哥哥', '13031' => '吸血姬', '13032' => '雪女', '13033' => '妖琴师', '13034' => '姑获鸟', '13035' => '镰鼬', '13036' => '惠比寿', '13037' => '络新妇', '13038' => '樱花妖', '13039' => '兵俑', '13040' => '丑时之女', '13041' => '独眼小僧', '13042' => '管狐', '13043' => '合同', '13044' => '蝴蝶精', '13045' => '椒图', '13046' => '觉', '13047' => '九命猫', '13048' => '礼貌', '13049' => '鲤鱼精', '13050' => '青蛙瓷器', '13051' => '三尾狐', '13052' => '白童子', '13053' => '黑童子', '13054' => '山童', '13055' => '山兔', '13056' => '食发鬼', '13057' => '跳跳弟弟', '13058' => '跳跳妹妹', '13059' => '铁鼠', '13060' => '童男', '13061' => '童女', '13062' => '巫蛊师', '13063' => '武士之灵', '13064' => '鸦天狗', '13065' => '萤草', '13066' => '雨女', '13067' => '座敷童子', '13068' => '饿鬼', '13069' => '首无'],
        //英雄联盟
        '14' => ['14001' => '卡蜜儿', '14002' => '艾翁', '14003' => '克烈', '14004' => '塔莉垭', '14005' => '索尔', '14006' => '烬', '14007' => '俄洛伊', '14008' => '千珏', '14009' => '塔姆', '14010' => '艾克', '14011' => '巴德', '14012' => '雷克赛', '14013' => '卡莉斯塔', '14014' => '阿兹尔', '14015' => '纳尔', '14016' => '布隆', '14017' => '维克兹', '14018' => '亚索', '14019' => '金克丝', '14020' => '卢锡安', '14021' => '亚托克斯', '14022' => '丽桑卓', '14023' => '扎克', '14024' => '奎因', '14025' => '锤石', '14026' => '蔚', '14027' => '娜美', '14028' => '劫', '14029' => '伊莉丝', '14030' => '卡兹克', '14031' => '辛德拉', '14032' => '雷恩加尔', '14033' => '黛安娜', '14034' => '婕拉', '14035' => '杰斯', '14036' => '德莱文', '14037' => '德莱厄斯', '14038' => '赫卡里姆', '14039' => '韦鲁斯', '14040' => '璐璐', '14041' => '菲奥娜', '14042' => '诺提勒斯', '14043' => '诺提勒斯', '14044' => '瑟庄妮', '14045' => '吉格斯', '14046' => '维克托', '14047' => '阿狸', '14048' => '沃利贝尔', '14049' => '菲兹', '14050' => '特朗德尔', '14051' => '拉克丝', '14052' => '布兰德', '14053' => '希瓦娜', '14054' => '格雷福斯', '14055' => '泽拉斯', '14056' => '图奇', '14057' => '锐雯', '14058' => '泰隆', '14059' => '斯卡纳', '14060' => '孙悟空', '14061' => '蕾欧娜', '14062' => '约里克', '14063' => '瑞兹', '14064' => '卡特琳娜', '14065' => '裟娜', '14066' => '斯维因', '14067' => '乐芙兰', '14068' => '艾瑞莉娅', '14069' => '卡西奥佩娅', '14070' => '凯特琳', '14071' => '雷克顿', '14072' => '卡尔玛', '14073' => '茂凯', '14074' => '嘉文四世', '14075' => '魔腾', '14076' => '李青', '14077' => '兰博', '14078' => '薇恩', '14079' => '奥莉安娜', '14080' => '科加斯', '14081' => '努努', '14082' => '阿木木', '14083' => '维迦', '14084' => '辛吉德', '14085' => '泰达米尔', '14086' => '蒙多', '14087' => '普朗克', '14088' => '墨菲特', '14089' => '希维尔', '14090' => '费德提克', '14091' => '凯尔', '14092' => '艾尼维亚', '14093' => '提莫', '14094' => '艾希', '14095' => '安妮', '14096' => '崔丝塔娜', '14097' => '贾克斯', '14098' => '易', '14099' => '库奇', '14100' => '阿里斯塔', '14101' => '布里兹', '14102' => '索拉卡', '14103' => '内瑟斯', '14104' => '沃里克', '14105' => '莫甘娜', '14106' => '拉莫斯', '14107' => '卡萨丁', '14108' => '赛恩', '14109' => '塔里克', '14110' => '迦娜', '14111' => '基兰', '14112' => '崔斯特', '14113' => '伊芙琳', '14114' => '卡尔萨斯', '14115' => '萨科', '14116' => '黑默丁格', '14117' => '阿卡丽', '14118' => '乌迪尔', '14119' => '盖伦', '14120' => '凯南', '14121' => '克格莫', '14122' => '马尔扎哈', '14123' => '莫德凯撒', '14124' => '奈德丽', '14125' => '伊泽瑞尔', '14126' => '古拉加斯', '14127' => '奥拉夫', '14128' => '潘森', '14129' => '波比', '14130' => '慎', '14131' => '赵信', '14132' => '弗拉基米尔', '14133' => '加里奥', '14134' => '厄加特', '14135' => '厄运小姐'],
        //甄嬛传
        '15' => ['15001' => '甄嬛', '15002' => '雍正', '15003' => '果郡王', '15004' => '皇后', '15005' => '太后', '15006' => '华妃', '15007' => '安陵容', '15008' => '沈眉庄', '15009' => '温实初', '15010' => '敬妃', '15011' => '端妃 ', '15012' => '欣贵人 ', '15013' => '齐妃 ', '15014' => '叶澜依', '15015' => '祺嫔 ', '15016' => '崔槿汐　', '15017' => '苏培盛 ', '15018' => '浣碧', '15019' => '流朱　', '15020' => '方淳意　', '15021' => '颂芝', '15022' => '曹琴默', '15023' => '富察贵人', '15024' => '瑛贵人', '15025' => '孟静娴', '15026' => '玉娆 ', '15027' => '敦福晋', '15028' => '剪秋', '15029' => '宝鹃', '15030' => '绘春', '15031' => '青樱']
    ];
    private $defalut_avatar_code = [];

    public function __construct(){
        $this->diaryListCacheModel  =   new DiaryListCacheModel();
        $this->initDefaultAvatarCode();
    }

    private function initDefaultAvatarCode($max = 50){
        for ($i=0; $i<$max; $i++){
            $this->defalut_avatar_code[$i] = 'http://d.fenfenriji.com/diary/anonymous/avatar/baby'.($i+1).'.png';
        }
    }

    function makeUidAnonymousNickname($code = null){
        $len = count($this->default_name_code);
        $newName = [];
        for($i = 1; $i < $len; $i++){
            $newName = $newName + $this->default_name_code[$i];
        }
        $nameCode = array_rand($newName); 
        if($code && $nameCode == $code){
            return $this->makeUidAnonymousNickname($code);
        }
        return $nameCode;
    }

    function anonymousNicknameCode2String($code){
        $index = intval($code/1000); 
        if($index > 0){
            return $this->default_name_code[$index][$code];
        }
        return $this->default_name_code[0];
    }

    /**
    *  根据code检测昵称是否存在范围内
    */
    function checkNicknameByCode($code){
        if($code < 0) return false;
        if($code > 0 && $code < 1000) return false;
        $index = intval($code/1000); 
        if($index > 0){
            return isset($this->default_name_code[$index][$code]) ? true : false;
        }
        return true;
    }

    function makeUidAnonymousAvatar($code = null){
        $len = count($this->defalut_avatar_code);
        $avatarCode = rand(0, $len-1);
        if($code && $avatarCode == $code){
            return $this->makeUidAnonymousAvatar($code);
        }
        return $avatarCode;
    }

    function anonymousAvatarCode2String($code){
        $avatar = $this->defalut_avatar_code[$code] ? $this->defalut_avatar_code[$code] : $this->defalut_avatar_code[0];
        return AC::getProtocolUriByOS($avatar);
    }

    /**
     * 获取单条信息
     * @param $bodyid
     * @return array|bool
     */
    function anonymousInfo($bodyid){
        $result = Storage::getDataByBodyidWithId(substr(self::ANONYMOUS_KEY_PREFIX, 0,-1), $bodyid, '*', 'id');
        return $result ? $result : [];
    }

    function updateAnonymous($param, $set){
        $uid = $param['uid'];
        $bodyid = $param['bodyId'];
        $cache_key = self::CC_ANONYMOUS_KEY.$bodyid;
        $this->diaryListCacheModel->removeStringByKey($cache_key);
        $key = self::ANONYMOUS_KEY_PREFIX .$uid;
        $where = ['id'=> intval($bodyid/1000) ];
        $result = Storage::setConditionData($key, $set, $where);
        if ($result && isset($set['status']) && $set['status']==1){
            $this->diaryListCacheModel->delAnonymousTimeline($bodyid);
        }
        return $result;
    }

    function getAnonymousInfoByBodyId($bodyid){
        $cache_key = self::CC_ANONYMOUS_KEY.$bodyid;
        $cache = $this->diaryListCacheModel->getStringByKey($cache_key);
        if ($cache)return json_decode($cache, true);
        $info = $this->anonymousInfo($bodyid);
        if (empty($info) || $info['status']!=0){
            AC::$errorNo    =   'AYS003';//不存在
            return  false;
        }
        $this->diaryListCacheModel->addStringByKey($cache_key, json_encode($info));
        return $info;
    }

    function getNewAnonymousInfo(){
        $key = self::ANONYMOUS_KEY_PREFIX.'0';
        $anonymousInfo = [];
        for($i = 0; $i < 32; $i++){
            $sql = "SELECT * FROM xxtshare.anonymous_{$i} WHERE status = 0 ORDER BY create_at DESC LIMIT 1";
            $result = Storage::fetchDbSentenceByClient($key, $sql);
            if(!$result) continue;
            $anonymousInfo[$result['create_at']] = $result;
        }
        ksort($anonymousInfo);
        return end($anonymousInfo);
    }

    function getNewAnonymousInfoByUid($uid){
        $key = self::ANONYMOUS_KEY_PREFIX.$uid;
        $where['uid'] = $uid;
        $where['status'] = 0;
        $order = " create_at desc";
        $info = Storage::getConditionData($key, $where, $order);
        return $info;
    }

    function removeAnonymousCache($bodyid){
        $cache_key = self::CC_ANONYMOUS_KEY.$bodyid;
        $this->diaryListCacheModel->removeStringByKey($cache_key);
    }

    /**
     * 解析anonymous表中extra字段
     * @param $extra
     * @return array
     */
    function parseAnonymousExtraField($extra){
        $ret = [
            'bg_type'=>'color',//color,image
            'bg_value'=>'',
            'title'=>''
        ];
        if ($info = json_decode($extra, true)){
            isset($info['bg_type']) && in_array($info['bg_type'], $this->bg_type_range ) && $ret['bg_type'] = $info['bg_type'];
            isset($info['bg_value']) && $ret['bg_value'] = trim($info['bg_value']);
            isset($info['title']) && $ret['title'] = trim($info['title']);
            $ret['bg_type']=='image' && $ret['bg_value'] = AC::getProtocolUriByOS(AC::$cdn_url_img).$ret['bg_value'];
        }
        return $ret;
    }

    function newAnonymousList($info){
        $bodyids = $this->diaryListCacheModel->getAnonymousNewList($info);
        if (empty($bodyids))return [];
        $list = [];
        foreach ($bodyids as $item) {
            $anonymous = $this->getAnonymousInfoByBodyId($item['bodyId']);
            if (AC::$errorNo){
                AC::$errorNo = null;
                continue;
            }
            $list[] = $anonymous;
        }
        return $list;
    }

    function userAnonymousList($uid, $start=0, $len=20){
        if (empty($uid) || $uid<1 || $start<0 || $len<1){
            AC::$errorNo    =   'AYS002';//不存在
            return  false;
        }
        $key = self::ANONYMOUS_KEY_PREFIX .$uid;
        $where = 'status=0';
        if ($start>1000){
            $start = $start/1000;
            $where .= ' and id<'.$start;
        }
        $result = Storage::getConditionManyData($key, $where, 'id desc', 0, $len);
        return $result ? $result : [];
    }

    function hotAnonymousList($id, $len){
        $bodyids = $this->diaryListCacheModel->getRecommendAnonymousList();
        if (empty($bodyids))return [];
        $list = [];
        $ids = array_keys($bodyids);
        $start = $id ? array_search($id, $ids) : -1;
        $start = $start==-1 ? 0 : $start+1;
        $ids = array_slice($ids, $start, $len);
        foreach ($ids as $item) {
            $anonymous = $this->getAnonymousInfoByBodyId($item);
            if (AC::$errorNo){
                AC::$errorNo = null;
                continue;
            }
            $list[] = $anonymous;
        }
        return $list;
    }

    function officialAnonymous(){
        $ret = [
            'showPos' => '-1',
            'list' => []
        ];
        $bodyids = $this->diaryListCacheModel->getOfficialAnonymousList();
        if (empty($bodyids))return $ret;
        $list = [];
        $ids = array_keys($bodyids);
        foreach ($ids as $item) {
            $anonymous = $this->getAnonymousInfoByBodyId($item);
            if (AC::$errorNo){
                AC::$errorNo = null;
                continue;
            }
            $list[] = $anonymous;
        }
        $ret['list'] = array_slice($list, 0, 3);
        if (!empty($ret['list'])){
            switch (count($ret['list'])){
                case 1:$ret['showPos'] = '0';break;
                case 2:$ret['showPos'] = '0,5';break;
                case 3:$ret['showPos'] = '0,5,10';break;
            }
        }
        return $ret;
    }

    function addAnonymous($data){
        $new = [
            'uid'=>$data['uid'],
            'type'=>0,
            'status'=>0,
            'attachment'=>$data['attachment'],
            'comment'=>0,
            'favorites'=>0,
            'nickname'=>$data['nickname'],
            'avatar'=>$data['avatar'],
            'content'=>$data['content'],
            'extra'=>$this->anonymousExtraParam2JsonString($data),
            'create_at'=> AC::SERVER_TIME
        ];
        $key = self::ANONYMOUS_KEY_PREFIX .$data['uid'];
        $result = Storage::addData($key, $new);
        return $result;
    }

    function addAnonymous2NewList($id, $uid){
        $bodyId = $id*1000 + UK::getHashId($uid, 32);
        $this->diaryListCacheModel->addAnonymousTimeline($bodyId);
    }

    /**
     * 提取extra所需参数组装成json
     * @param $param
     * @return string
     */
    function anonymousExtraParam2JsonString($param){
        $extra = [
            'bg_type'=>'color',
            'bg_value'=>'',
            'title'=>'',
        ];
        if (isset($param['bg_type']) && in_array($param['bg_type'], $this->bg_type_range )){
            $extra['bg_type'] = $param['bg_type'];
        }
        if (isset($param['bg_value'])){
            $extra['bg_value'] = trim($param['bg_value']);
        }
        if (isset($param['title'])){
            $extra['title'] = trim($param['title']);
        }
        return UK::JsonFormat($extra);
    }

    function getFavoriteInfoByBodyId($bodyid, $uid, $position){
        $cache_key = self::LIKE_ANONYMOUS_KEY.$bodyid.':'.$position.':'.$uid;
        $cache = $this->diaryListCacheModel->getStringByKey($cache_key);
        if ($cache)return json_decode($cache, true);
        $key = self::FAVORITE_KEY_PREFIX .$uid;
        $where = " bodyid = {$bodyid} and position = {$position}";
        $info = Storage::getConditionData($key, $where);
        $info && $this->diaryListCacheModel->addStringByKey($cache_key, json_encode($info));
        return $info ? $info : [];
    }

    function addFavorite($data){
        $new = [
            'uid' => $data['uid'],
            'bodyid' => $data['bodyId'],
            'position' => $data['position'],
            'status' => 0,
            'create_at' => AC::SERVER_TIME
        ];
        $key = self::FAVORITE_KEY_PREFIX .$data['uid'];
        $result = Storage::addData($key, $new);
        return $result;
    }

    function removeFavorite($bodyid, $uid, $position){
        $cache_key = self::LIKE_ANONYMOUS_KEY.$bodyid.':'.$position.':'.$uid;
        $this->diaryListCacheModel->removeStringByKey($cache_key);
        $key = self::FAVORITE_KEY_PREFIX .$uid;
        $where = " bodyid = {$bodyid} and position = {$position}";
        $info = Storage::delConditionData($key, $where);
        return $info ? $info : [];
    }

    function getCommentListByBodyId($bodyid, $start=0, $len=20, $sort = 'all'){
        if (empty($bodyid) || $bodyid<1000 || $start<0 || $len<1){
            AC::$errorNo    =   'AYS001';//参数错误
            return  false;
        }
        $key = self::COMMENT_KEY_PREFIX .$bodyid;
        /*$where = 'cid='.$bodyid.' AND status=0';
        if ($start>0){
            $where .= ' and position>'.$start;
        }*/
        list($where, $orderBy) = $this->getCommentsBySequence($bodyid,$sort,$start);
        $result = Storage::getConditionManyData($key, $where, $orderBy, 0, $len);
        return $result ? $result : [];
    }

    /**
     * 获取分页相关条件
     * @param unknown $cid
     * @param string $sort
     * @param number $author_uid
     * @param number $id
     * @return multitype:Ambigous <multitype:, string> string
     */
    private function getCommentsBySequence ($cid, $sort = 'all', $id = 0) {
        switch ($sort){
            case 'hot':
                $where  =   array('cid' => $cid);
                $orderBy=   ' favorites DESC ';
                break;
            case 'up':
                $where  =   " `cid` = ".$cid . ' AND `status` = 0';
                if ($id > 0) {
                    $where .= ' AND `position` > '.$id;
                    $orderBy=   ' position ASC ';
                }else{
                    $orderBy=   ' position DESC ';
                }
                break;
            case 'down':
                $where  =   " `cid` = ".$cid . ' AND `status` = 0';
                if ($id > 0) {
                    $where .= ' AND `position` < '.$id;
                }
                
                $orderBy=   ' position DESC ';
                break;
            default:
                $where  =   " `cid` = ".$cid . ' AND `status` = 0';
                if ($id > 0) {
                    $where .= ' AND `position` > '.$id;
                }
                
                $orderBy=   ' position ASC ';
        }
        
        return array($where, $orderBy);
    }

    function getCommentInfoByBodyIdPos($bodyid, $pos){
        if (empty($bodyid) || empty($pos) || $bodyid<1000 || $pos<0){
            AC::$errorNo    =   'AYS001';//参数错误
            return  false;
        }
        $key = self::COMMENT_KEY_PREFIX .$bodyid;
        $where = 'cid='.$bodyid. ' AND position='.$pos;
        $result = Storage::getConditionData($key, $where);
        return $result ? $result : [];
    }

    function getCommentInfoByBodyIdUid($bodyid, $uid, $status = 0){
        if (empty($bodyid) || empty($uid) || $bodyid<1000 || $uid<0){
            AC::$errorNo    =   'AYS001';//参数错误
            return  false;
        }
        $key = self::COMMENT_KEY_PREFIX .$bodyid;
        if($status){
            $where = 'cid='.$bodyid. ' AND uid='.$uid;
        }else{
            $where = 'cid='.$bodyid. ' AND uid='.$uid .' AND status='.$status;    
        }
        $result = Storage::getConditionData($key, $where);
        return $result ? $result : [];
    }

    function addComment($data){
        $new = [
            'cid' => $data['bodyId'],
            'uid' => $data['uid'],
            'nickname' => $data['nickname'],
            'avatar' => $data['avatar'],
            'parentId' => isset($data['parentId']) ? intval($data['parentId']) : 0,
            'content' => $data['content'],
            'create_at' => AC::SERVER_TIME,
            'status' => 0,
            'attachment' => $data['attachment']
        ];
        $key = self::COMMENT_KEY_PREFIX .$data['bodyId'];
        $result = Storage::addData($key, $new);
        return $result;
    }

    function updateComment($param, $set){
        $bodyid = $param['bodyId'];
        $pos = $param['pos'];
        $uid = $param['uid'];
        $key = self::COMMENT_KEY_PREFIX .$bodyid;
        $where = ['cid'=>$bodyid, 'position'=>$pos, 'uid'=>$uid];
        $result = Storage::setConditionData($key, $set, $where);
        return $result ;
    }

    public function checkCommentRepet($uid, $bodyid, $content){
        $lastCk = $this->diaryListCacheModel->getAnonyCheckConnent($uid, $bodyid);
        if($lastCk && $lastCk == $content){
            AC::$errorNo    =   'DC111';
            AC::$errorMsg   =   '话题评论内容重复提交';
            return  FALSE;
        }
        return $content;
    }

    function addMessage($data){
        $new = [
            'uid' => $data['uid'],
            'bodyid' => $data['bodyId'],
            'position' => intval($data['position']),
            'rUid' => $data['uid'],
            'avatar' => $data['avatar'],
            'nickname' => $data['nickname'],
            'type' => $data['type'],
            'read' => 1,
            'status' => 0,
            'content' => $data['content'],
            'create_at' => AC::SERVER_TIME
        ];
        $key = self::MESSAGE_KEY_PREFIX .$data['uid'];
        $result = Storage::addData($key, $new);
        return $result;
    }

    function clearMessage($uid){
        $key = self::MESSAGE_KEY_PREFIX .$uid;
        $set = ['status'=>1];
        return Storage::setConditionData($key, $set, ['uid'=>$uid]);
    }

    function removeMessage($uid, $id){
        $key = self::MESSAGE_KEY_PREFIX .$uid;
        $set = ['status'=>1];
        return Storage::setConditionData($key, $set, ['id'=>$id, 'uid'=>$uid]);
    }

    function flagMessageDelByBodyidPos($uid, $bodyid, $pos){
        $key = self::MESSAGE_KEY_PREFIX .$uid;
        $set = ['status'=>2];
        return Storage::setConditionData($key, $set, ['uid'=>$uid, 'bodyid'=>$bodyid, 'position'=>$pos  ]);
    }

    function removeidsMessage($uid, $ids){
        $key = self::MESSAGE_KEY_PREFIX .$uid;
        $set = ['status'=>1];
        $where = 'uid="'.$uid.'" and id IN ('. $ids .') ';
        return Storage::setConditionData($key, $set, $where);
    }

    function getMessageList($uid, $id, $len){
        if (empty($uid) || $uid<1 || $id<0 || $len<1){
            AC::$errorNo    =   'AYS001';//参数错误
            return  false;
        }
        $key = self::MESSAGE_KEY_PREFIX .$uid;
        $where = 'uid='.$uid. ' AND status!=1 ';
        if ($id>0){
            $where .= ' and id<'.$id;
        }
        $result = Storage::getConditionManyData($key, $where, 'id desc', 0, $len);
        return $result ? $result : [];
    }

}